package cn.lxg.controller.common;

import cn.lxg.pojo.TUser;
import cn.lxg.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(value = "/page")
public class RegisterController {
    @Autowired
    private final IUserService userService = null;

    @PostMapping(value = "/register")
    public String register(Model model, TUser user) {
        // 参数预处理
        user.setName(user.getName().trim());
        user.setAccount(user.getAccount().trim());

        // 准备数据
        String msg = this.userService.add(user);

        // 传输数据给前端
        model.addAttribute("msg", msg.replaceAll("添加", "注册"));

        return "common/message";
    }
}
